
#include "Socket.hpp"
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
#include <unistd.h>
using namespace std;

// ./tcpclient serverip serverport
int main(int argc, char *argv[])
{
    if (argc != 3)
    {
        std::cout << "Usage : " << argv[0] << " serverip serverport" << std::endl;
        return 0;
    }
    std::string serverip = argv[1];
    uint16_t serverport = std::stoi(argv[2]);

    Net_Work::Socket *conn = new Net_Work::TcpSocket();
    if (!conn->BuildConnectSocketMethod(serverip, serverport))
    {
        std::cerr << "connect " << serverip << ":" << serverport << " failed" << std::endl;
    }
    std::cout << "connect " << serverip << ":" << serverport << " success" << std::endl;
        // 1. 构建一个请求，遵守协议
        // 2. 对请求进行序列化
        std::string requeststr="你好";
        cout<<"发送消息:"<<requeststr<<endl;
        conn->Send(requeststr);
        std::string responsestr;
            // 5. 读取响应
         conn->Recv(&responsestr, 1024);
         cout<<"收到消息:"<<endl;
         cout<<responsestr<<endl;
            // 6. 报文进行解析
            

    conn->CloseSocket();
    return 0;
}
